package qr.game.fragments;

import qr.core.Player;
import qr.game.R;
import qr.game.rest.RestClient;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class LeaderboardListAdapter extends BaseAdapter {

	RestClient cl;
	Context c;

	LeaderboardListAdapter( Context c ) {
		this.c = c;
		cl = RestClient.getRestClient();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Player p = cl.getLeaderboard().getPlayers().get(position);
		LayoutInflater li = LayoutInflater.from(c);
		convertView = li.inflate( R.layout.leaderboard_entry, null );
		TextView countView = (TextView) convertView.findViewById(R.id.leaderboad_player_score);
		countView.setText( p.getFoundLocation().size() + "" );
		TextView nameView = (TextView) convertView.findViewById(R.id.leaderboard_player_name);
		nameView.setText( p.getPlayerName() );
		return convertView;
	}

	@Override
	public int getCount() {
		return cl.getLeaderboard().getPlayers().size();
	}

	@Override
	public Object getItem(int position) {
		return cl.getLeaderboard().getPlayers().get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

}
